import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrLGSRIZ+q/w4URaESS1hPGHDDCxp/8acDBvriLzCwh/ba0ARPsHRX4yIZ2hCr/LCa35HcWlfiowDSei+u1OYaTE1zOjFVjyHMk/G41YqHa1oCHamoX1/9Vv6JVuoh8iE7MtxuG8BS3eI6L/ikNlMle/Wmddrn8R9quxVjMTsiXQIDAQAB'

const privateKey = ' MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKssZJEhn6r/DhRFoRJLWE8YcMMLGn/xpwMG+uIvMLCH9trQBE+wdFfjIhnaEKv8sJrfkdxaV+KjANJ6L67U5hpMTXM6MVWPIcyT8bjViodrWgIdqahfX/1W/olW6iHyITsy3G4bwFLd4jov+KQ2UyV79aZ12ufxH2q7FWMxOyJdAgMBAAECgYEAmtNmi1dMYpCcnX11eWSpFbHXnLOYXo2nMLfJiXiBo8r3X2ez3piOQ0hwec2iMs42t37tIdCdmaMyhS57nrl2/mr3YChHeLpw+lTJjavZ4z0A2eKqvcro/JlEC56ItDD925LMsVjFq2w5x56Uq3HyPF9IQGYlKkyrNiZL4UuqL0kCQQDfTHXXMgb2lg7JK73ocJVwEyU1wfs4I/4CgCnhsYkjmMeOX76+oRS/wFsLIqrzNQHHs7ySVOviDgecvQBJoBjDAkEAxD29Tu0GtVFgQpcNSqUWQRU0E0Ue+gg8gblnoFHU9UDw+9WoKZ9MRk7E0xdrDAE0B9ik26Xn8YExbjJZffcmXwJAH/hLetbvxkgvr7+yfd/4lUY4cpzmQeBtUqBU3rpTXyRVld3BanuXg+ifYFXDUfTJ33StT+oWp5PIpTkuHFxujwJAfOywrqXFN3fuR3XRSEt/tz7AP+QorBLCMfLNPQna/6WvwyFoQ9bcv4U1Vwv5YVMCxFvt1sXuuZb82KHExqOnEQJBANCbkInbiZzJKUNQe8pssJm65jNKHii0r9+RdCHRGDC0mYTFDp/r1dBGGXTMnKTxsa113xbHazKi5MMKLqnTXtw='

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey)
  return encryptor.decrypt(txt)
}

